package com.aspose.cells;

public class SparklineCollection extends CollectionBase {
   private SparklineGroup b;

   SparklineCollection(SparklineGroup group, String dataRange, boolean isVertical, CellArea locationRange) {
      this.b = group;
      this.a(dataRange, isVertical, locationRange);
   }

   SparklineCollection(SparklineGroup group) {
      this.b = group;
   }

   void a(CellArea var1) {
      int var2 = this.b(var1);
      if (var2 != this.a.size()) {
         throw new CellsException(6, "Invalid Location range");
      } else {
         int var3;
         Sparkline var4;
         if (var1.StartColumn == var1.EndColumn) {
            for(var3 = 0; var3 < var2; ++var3) {
               var4 = (Sparkline)this.a.get(var3);
               var4.a(var1.StartRow + var3);
               var4.b(var1.StartColumn);
            }
         } else {
            if (var1.StartRow != var1.EndRow) {
               throw new CellsException(6, "Location reference cells must in same column or row");
            }

            for(var3 = 0; var3 < var2; ++var3) {
               var4 = (Sparkline)this.a.get(var3);
               var4.a(var1.StartRow);
               var4.b(var1.StartColumn + var3);
            }
         }

      }
   }

   void a(String var1, boolean var2, CellArea var3) {
      zboa var4 = new zboa(this.b());
      var4.a(var1);
      var4.c();
      if (var2) {
         if (var4.j != var4.k) {
            throw new CellsException(6, "The reference for the data range is invalid");
         }
      } else if (var4.h != var4.i) {
         throw new CellsException(6, "The reference for the data range is invalid");
      }

      int var5 = this.a(var4, var2);
      if (var5 != this.b(var3)) {
         throw new CellsException(6, "The reference for the location or data range is invalid");
      } else {
         this.a.clear();

         for(int var6 = 0; var6 < var5; ++var6) {
            Sparkline var7 = new Sparkline(this);
            com.aspose.cells.b.a.a.ze.a(this.a, (Object)var7);
         }

         this.b(var4, var2);
         this.a(var3);
      }
   }

   SparklineGroup a() {
      return this.b;
   }

   public Sparkline get(int index) {
      return (Sparkline)this.a.get(index);
   }

   void a(Sparkline var1) {
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
   }

   public int add(String dataRange, int row, int column) {
      Sparkline var4 = new Sparkline(this);
      var4.setDataRange(dataRange);
      var4.a(row);
      var4.b(column);
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var4);
      return this.a.size() - 1;
   }

   public void remove(Object o) {
      this.a.remove((Sparkline)o);
   }

   Worksheet b() {
      return this.b.a().a();
   }

   WorksheetCollection c() {
      return this.b.a().a().getWorkbook().getWorksheets();
   }

   private int a(zboa var1, boolean var2) {
      return var2 ? var1.g - var1.e + 1 : var1.f - var1.d + 1;
   }

   private int b(CellArea var1) {
      if (var1.StartColumn == var1.EndColumn) {
         return var1.EndRow - var1.StartRow + 1;
      } else if (var1.StartRow == var1.EndRow) {
         return var1.EndColumn - var1.StartColumn + 1;
      } else {
         throw new CellsException(6, "Location reference cells must in same column or row");
      }
   }

   private void b(zboa var1, boolean var2) {
      int var3 = this.a(var1, var2);
      if (var3 != this.a.size()) {
         throw new CellsException(6, "Invalid data range");
      } else {
         int var4;
         String var5;
         String var6;
         Sparkline var7;
         if (var2) {
            for(var4 = 0; var4 < var3; ++var4) {
               var5 = this.a(var1.d, var1.h, var4 + var1.e, var1.j);
               var6 = this.a(var1.f, var1.i, var4 + var1.e, var1.j);
               var7 = (Sparkline)this.a.get(var4);
               var7.setDataRange(this.a(var1.c) + "!" + var5 + ":" + var6);
            }
         } else {
            for(var4 = 0; var4 < var3; ++var4) {
               var5 = this.a(var4 + var1.d, var1.h, var1.e, var1.j);
               var6 = this.a(var4 + var1.d, var1.h, var1.g, var1.k);
               var7 = (Sparkline)this.a.get(var4);
               var7.setDataRange(this.a(var1.c) + "!" + var5 + ":" + var6);
            }
         }

      }
   }

   private String a(String var1) {
      return zakq.b(var1) ? "'" + var1 + "'" : var1;
   }

   private String a(int var1, boolean var2, int var3, boolean var4) {
      zakq.a(var1, var3);
      ++var1;
      StringBuilder var5 = new StringBuilder();
      if (var4) {
         var5.append("$");
      }

      var5.append(CellsHelper.columnIndexToName(var3));
      if (var2) {
         var5.append("$");
      }

      var5.append(com.aspose.cells.b.a.zo.a(var1));
      return com.aspose.cells.b.a.zr.a(var5);
   }

   int a(Cells var1, int var2, int var3, boolean var4) {
      for(int var5 = 0; var5 < this.a.size(); ++var5) {
         Sparkline var6 = (Sparkline)this.a.get(var5);
         if (var6.a(var1, var2, var3, var4)) {
            this.remove(var6);
         }
      }

      return this.getCount();
   }

   int b(Cells var1, int var2, int var3, boolean var4) {
      for(int var5 = 0; var5 < this.a.size(); ++var5) {
         Sparkline var6 = (Sparkline)this.a.get(var5);
         if (var6.b(var1, var2, var3, var4)) {
            this.remove(var6);
         }
      }

      return this.getCount();
   }
}
